#define LOG_TAG "LCM"

#ifndef BUILD_LK
#include <linux/string.h>
#include <linux/kernel.h>
#endif

#include "lcm_drv.h"

#ifdef BUILD_LK
#include <platform/upmu_common.h>
#include <platform/mt_gpio.h>
#include <platform/mt_i2c.h>
#include <platform/mt_pmic.h>
#include <string.h>
#elif defined(BUILD_UBOOT)
#include <asm/arch/mt_gpio.h>
#else
#include <mach/mt_pm_ldo.h>
#include <mach/mt_gpio.h>
#endif

#ifdef BUILD_LK
#define LCM_LOGI(string, args...)  dprintf(0, "[LK/"LOG_TAG"]"string, ##args)
#define LCM_LOGD(string, args...)  dprintf(1, "[LK/"LOG_TAG"]"string, ##args)
#else
#define LCM_LOGI(fmt, args...)  pr_debug("[KERNEL/"LOG_TAG"]"fmt, ##args)
#define LCM_LOGD(fmt, args...)  pr_debug("[KERNEL/"LOG_TAG"]"fmt, ##args)
#endif

static LCM_UTIL_FUNCS lcm_util;

#define SET_RESET_PIN(v)			(lcm_util.set_reset_pin((v)))
#define MDELAY(n)					(lcm_util.mdelay(n))

/* --------------------------------------------------------------------------- */
/* Local Functions */
/* --------------------------------------------------------------------------- */
#define dsi_set_cmdq_V2(cmd, count, ppara, force_update) \
	lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
#define dsi_set_cmdq(pdata, queue_size, force_update) \
	lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
#define wrtie_cmd(cmd) \
	lcm_util.dsi_write_cmd(cmd)
#define write_regs(addr, pdata, byte_nums) \
	lcm_util.dsi_write_regs(addr, pdata, byte_nums)
#define read_reg(cmd) \
	lcm_util.dsi_dcs_read_lcm_reg(cmd)
#define read_reg_v2(cmd, buffer, buffer_size) \
	lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
#define set_gpio_lcd_enp(cmd) \
		lcm_util.set_gpio_lcd_enp_bias(cmd)
		

static const unsigned char LCD_MODULE_ID = 0x01;
/* --------------------------------------------------------------------------- */
/* Local Constants */
/* --------------------------------------------------------------------------- */
#define LCM_DSI_CMD_MODE	0
#define FRAME_WIDTH  										 (720)
#define FRAME_HEIGHT 										 (1600)

#define REGFLAG_DELAY             							 0xFFFA
#define REGFLAG_UDELAY             							 0xFFFB
#define REGFLAG_PORT_SWAP									 0xFFFC
#define REGFLAG_END_OF_TABLE      							 0xFFFD   // END OF REGISTERS MARKER

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

#define LCM_ID_NT36525_TIANMA (0x80)

/* --------------------------------------------------------------------------- */
/* Local Variables */
/* --------------------------------------------------------------------------- */

struct LCM_setting_table
{
    unsigned int cmd;
    unsigned char count;
    unsigned char para_list[64];
};

static struct LCM_setting_table lcm_suspend_setting[] =
{
    {0x28, 1, {0x00}},
    {REGFLAG_DELAY, 10, {}},
    {0x10, 1, {0x00}},
    {REGFLAG_DELAY, 60, {} },
};

static struct LCM_setting_table lcm_initialization_setting[] =
{
{0xFF,1,{0x20}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0x01,1,{0x55}},
{0x03,1,{0x55}},
{0x05,1,{0x99}},
{0x07,1,{0x4B}},
{0x08,1,{0xDF}},
{0x0E,1,{0x69}},
{0x0F,1,{0x7D}},
{0x89,1,{0xBD}},//--VCOM
{0x8A,1,{0xBD}},//--VCOM
{0x8B,1,{0xBD}},//--VCOM
{0x8C,1,{0xBD}},//--VCOM
{0x94,1,{0xC0}},
{0x95,1,{0x13}},
{0x96,1,{0x13}},
{0x69,1,{0x91}},
{0x1F,1,{0x02}},
{0xFF,1,{0x20}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0xB0,16,{0x00,0x00,0x00,0x01,0x00,0x2E,0x00,0x46,0x00,0x5A,0x00,0x6D,0x00,0x7E,0x00,0x8F}},
{0xB1,16,{0x00,0x9D,0x00,0xD3,0x00,0xFC,0x01,0x40,0x01,0x71,0x01,0xC5,0x02,0x03,0x02,0x06}},
{0xB2,16,{0x02,0x44,0x02,0x87,0x02,0xB6,0x02,0xEB,0x03,0x13,0x03,0x3E,0x03,0x50,0x03,0x5F}},
{0xB3,12,{0x03,0x73,0x03,0x8B,0x03,0xA9,0x03,0xC7,0x03,0xD9,0x03,0xDC}},
{0xB4,16,{0x00,0x00,0x00,0x01,0x00,0x2E,0x00,0x46,0x00,0x5A,0x00,0x6D,0x00,0x7E,0x00,0x8F}},
{0xB5,16,{0x00,0x9D,0x00,0xD3,0x00,0xFC,0x01,0x40,0x01,0x71,0x01,0xC5,0x02,0x03,0x02,0x06}},
{0xB6,16,{0x02,0x44,0x02,0x87,0x02,0xB6,0x02,0xEB,0x03,0x13,0x03,0x3E,0x03,0x50,0x03,0x5F}},
{0xB7,12,{0x03,0x73,0x03,0x8B,0x03,0xA9,0x03,0xC7,0x03,0xD9,0x03,0xDC}},
{0xB8,16,{0x00,0x00,0x00,0x01,0x00,0x2E,0x00,0x46,0x00,0x5A,0x00,0x6D,0x00,0x7E,0x00,0x8F}},
{0xB9,16,{0x00,0x9D,0x00,0xD3,0x00,0xFC,0x01,0x40,0x01,0x71,0x01,0xC5,0x02,0x03,0x02,0x06}},
{0xBA,16,{0x02,0x44,0x02,0x87,0x02,0xB6,0x02,0xEB,0x03,0x13,0x03,0x3E,0x03,0x50,0x03,0x5F}},
{0xBB,12,{0x03,0x73,0x03,0x8B,0x03,0xA9,0x03,0xC7,0x03,0xD9,0x03,0xDC}},
{0xFF,1,{0x21}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0xB0,16,{0x00,0x00,0x00,0x01,0x00,0x26,0x00,0x3E,0x00,0x52,0x00,0x65,0x00,0x76,0x00,0x87}},
{0xB1,16,{0x00,0x95,0x00,0xCB,0x00,0xF4,0x01,0x38,0x01,0x69,0x01,0xBD,0x01,0xFB,0x01,0xFE}},
{0xB2,16,{0x02,0x3C,0x02,0x7F,0x02,0xAE,0x02,0xE3,0x03,0x0B,0x03,0x36,0x03,0x48,0x03,0x57}},
{0xB3,12,{0x03,0x6B,0x03,0x83,0x03,0xA1,0x03,0xBF,0x03,0xD9,0x03,0xDC}},
{0xB4,16,{0x00,0x00,0x00,0x01,0x00,0x26,0x00,0x3E,0x00,0x52,0x00,0x65,0x00,0x76,0x00,0x87}},
{0xB5,16,{0x00,0x95,0x00,0xCB,0x00,0xF4,0x01,0x38,0x01,0x69,0x01,0xBD,0x01,0xFB,0x01,0xFE}},
{0xB6,16,{0x02,0x3C,0x02,0x7F,0x02,0xAE,0x02,0xE3,0x03,0x0B,0x03,0x36,0x03,0x48,0x03,0x57}},
{0xB7,12,{0x03,0x6B,0x03,0x83,0x03,0xA1,0x03,0xBF,0x03,0xD9,0x03,0xDC}},
{0xB8,16,{0x00,0x00,0x00,0x01,0x00,0x26,0x00,0x3E,0x00,0x52,0x00,0x65,0x00,0x76,0x00,0x87}},
{0xB9,16,{0x00,0x95,0x00,0xCB,0x00,0xF4,0x01,0x38,0x01,0x69,0x01,0xBD,0x01,0xFB,0x01,0xFE}},
{0xBA,16,{0x02,0x3C,0x02,0x7F,0x02,0xAE,0x02,0xE3,0x03,0x0B,0x03,0x36,0x03,0x48,0x03,0x57}},
{0xBB,12,{0x03,0x6B,0x03,0x83,0x03,0xA1,0x03,0xBF,0x03,0xD9,0x03,0xDC}},
{0xFF,1,{0x23}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0x12,1,{0xB4}},
{0x15,1,{0xE9}},
{0x16,1,{0x0B}},

{0xFF,1,{0x24}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0x93,1,{0x0A}},
{0x94,1,{0x0A}},
{0x00,1,{0x00}},
{0x01,1,{0x1E}},
{0x02,1,{0x1D}},
{0x03,1,{0x21}},
{0x04,1,{0x04}},
{0x05,1,{0x05}},
{0x06,1,{0x1F}},
{0x07,1,{0x20}},
{0x08,1,{0x0C}},
{0x09,1,{0x0D}},
{0x0A,1,{0x0E}},
{0x0B,1,{0x0F}},
{0x0C,1,{0x00}},
{0x0D,1,{0x00}},
{0x0E,1,{0x00}},
{0x0F,1,{0x00}},
{0x10,1,{0x00}},
{0x11,1,{0x00}},
{0x12,1,{0x00}},
{0x13,1,{0x00}},
{0x14,1,{0x00}},
{0x15,1,{0x00}},
{0x16,1,{0x00}},
{0x17,1,{0x1E}},
{0x18,1,{0x1D}},
{0x19,1,{0x21}},
{0x1A,1,{0x04}},
{0x1B,1,{0x05}},
{0x1C,1,{0x1F}},
{0x1D,1,{0x20}},
{0x1E,1,{0x0C}},
{0x1F,1,{0x0D}},
{0x20,1,{0x0E}},
{0x21,1,{0x0F}},
{0x22,1,{0x00}},
{0x23,1,{0x00}},
{0x24,1,{0x00}},
{0x25,1,{0x00}},
{0x26,1,{0x00}},
{0x27,1,{0x00}},
{0x28,1,{0x00}},
{0x29,1,{0x00}},
{0x2A,1,{0x00}},
{0x2B,1,{0x00}},
{0x2F,1,{0x08}},
{0x30,1,{0x06}},
{0x31,1,{0x00}},
{0x32,1,{0x00}},
{0x33,1,{0x06}},
{0x34,1,{0x08}},
{0x35,1,{0x00}},
{0x36,1,{0x00}},
{0x37,1,{0x44}},
{0x38,1,{0x44}},
{0x39,1,{0x00}},
{0x3A,1,{0x24}},
{0x3B,1,{0x88}},
{0x3D,1,{0x52}},
{0x4D,1,{0x34}},
{0x4E,1,{0x12}},
{0x4F,1,{0x00}},
{0x50,1,{0x00}},
{0x51,1,{0x21}},
{0x52,1,{0x43}},
{0x53,1,{0x00}},
{0x54,1,{0x00}},
{0x55,1,{0x47}},
{0x56,1,{0x44}},
{0x58,1,{0x21}},
{0x59,1,{0x00}},
{0x5A,1,{0x24}},
{0x5B,1,{0x88}},
{0x5C,1,{0x80}},
{0x5D,1,{0x0F}},
{0x5E,1,{0x04}},
{0x5F,1,{0x00}},
{0x88,1,{0x2E}},
{0x89,1,{0x40}},
{0x8A,1,{0x8F}},
{0x8D,1,{0x00}},
{0x8E,1,{0x0F}},
{0x60,1,{0x80}},
{0x61,1,{0x90}},
{0x64,1,{0x10}},

// BOE modify
{0x80,1,{0x08}},
{0x81,1,{0x04}},
{0x82,1,{0x08}},
{0x83,1,{0x04}},
{0x84,1,{0x00}},
{0x85,1,{0x01}},
{0x86,1,{0x04}},
{0x91,1,{0x40}},
{0x92,1,{0xA7}},
{0x98,1,{0x80}},
{0xAB,1,{0x00}},
{0xAD,1,{0x00}},
{0xAF,1,{0x04}},
{0xB0,1,{0x05}},
{0xB1,1,{0xA3}},

{0xFF,1,{0x25}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0x17,1,{0x82}},
{0x18,1,{0x06}},
{0x19,1,{0x0F}},
{0x1E,1,{0x00}},
{0x1F,1,{0x24}},
{0x20,1,{0x88}},
{0x23,1,{0x05}},
{0x24,1,{0xA3}},
{0x25,1,{0x00}},
{0x26,1,{0x24}},
{0x27,1,{0x88}},
{0x2A,1,{0x05}},
{0x2B,1,{0xA3}},
{0x2F,1,{0x55}},
{0x30,1,{0x11}},
{0x31,1,{0x00}},
{0x32,1,{0x00}},
{0x33,1,{0x24}},
{0x34,1,{0x88}},
{0x37,1,{0x05}},
{0x38,1,{0xA3}},
{0x40,1,{0x11}},
{0x41,1,{0x80}},
{0x42,1,{0x24}},
{0x43,1,{0x88}},
{0x46,1,{0x05}},
{0x47,1,{0xA3}},
{0x49,1,{0x00}},
{0x4A,1,{0x00}},
{0x4B,1,{0x24}},
{0x4C,1,{0x88}},
{0x4F,1,{0x24}},
{0x50,1,{0x88}},
{0x53,1,{0x05}},
{0x54,1,{0xA3}},
{0x55,1,{0x05}},
{0x56,1,{0xA3}},
{0x5A,1,{0x22}},
{0x5B,1,{0xC0}},
{0x5C,1,{0x00}},
{0x5D,1,{0x24}},
{0x5E,1,{0x88}},
{0x61,1,{0x24}},
{0x62,1,{0x88}},
{0x65,1,{0x05}},
{0x66,1,{0xA3}},
{0x8A,1,{0x00}},
{0xC0,1,{0x07}},
{0xC2,1,{0x84}},
{0xC6,1,{0x92}},
{0xCA,1,{0x1C}},
{0xCC,1,{0x1C}},
{0xCD,1,{0x00}},
{0xCE,1,{0x00}},
{0xD3,1,{0x11}},
{0xD4,1,{0xCC}},
{0xD5,1,{0x11}},
{0xD6,1,{0x1C}},
{0xD7,1,{0x11}},
{0x0A,1,{0x82}},
{0x0B,1,{0x79}},
{0x0C,1,{0x01}},

{0xFF,1,{0x26}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0x00,1,{0xA1}},
{0x04,1,{0x4A}},
{0x06,1,{0xFF}},
{0x0C,1,{0x0B}},
{0x0D,1,{0x01}},
{0x0E,1,{0x02}},
{0x0F,1,{0x06}},
{0x10,1,{0x07}},
{0x11,1,{0x00}},
{0x13,1,{0x28}},
{0x14,1,{0x90}},
{0x16,1,{0x81}},
{0x19,1,{0x1A}},
{0x1A,1,{0x0D}},
{0x1B,1,{0x12}},
{0x1C,1,{0x82}},
{0x1D,1,{0x00}},
{0x1E,1,{0xA7}},
{0x1F,1,{0xA7}},
{0x24,1,{0x00}},
{0x25,1,{0xA7}},
{0x26,1,{0x66}},
{0x27,1,{0x66}},
{0x28,1,{0x66}},
{0x29,1,{0x06}},
{0x2F,1,{0x02}},
{0x30,1,{0xA7}},
{0x31,1,{0x11}},
{0x32,1,{0x11}},
{0x34,1,{0x03}},
{0x35,1,{0xA7}},
{0x36,1,{0x78}},
{0x37,1,{0x66}},
{0x38,1,{0x66}},
{0x39,1,{0x06}},
{0x3F,1,{0x04}},
{0x40,1,{0xA7}},
{0x41,1,{0x00}},
{0x42,1,{0x00}},
{0x43,1,{0x00}},

{0xFF,1,{0x26}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0x58,1,{0xCC}},
{0x59,1,{0xCC}},
{0x5A,1,{0xCC}},
{0x5B,1,{0xCC}},
{0x5C,1,{0x00}},
{0x5D,1,{0x00}},
{0x5E,1,{0x04}},
{0x5F,1,{0x00}},
{0x60,1,{0x00}},
{0x61,1,{0x00}},
{0x63,1,{0x24}},
{0x64,1,{0x88}},
{0x67,1,{0x24}},
{0x68,1,{0x88}},
{0x6B,1,{0x00}},
{0x6C,1,{0x05}},
{0x6D,1,{0x00}},
{0x70,1,{0x05}},
{0x71,1,{0xC8}},
{0x73,1,{0x24}},
{0x74,1,{0x88}},
{0x77,1,{0x05}},
{0x78,1,{0xC8}},
{0x79,1,{0x00}},
{0x7A,1,{0x24}},
{0x7B,1,{0x88}},
{0x7E,1,{0x05}},
{0x7F,1,{0xC8}},
{0x80,1,{0x00}},
{0x81,1,{0x00}},
{0x82,1,{0x24}},
{0x83,1,{0x88}},
{0x86,1,{0x24}},
{0x87,1,{0x88}},
{0x8A,1,{0x05}},
{0x8B,1,{0xC8}},
{0x8C,1,{0x00}},
{0x8D,1,{0x00}},
{0x8E,1,{0x01}},
{0x8F,1,{0x00}},
{0x90,1,{0x00}},
{0x91,1,{0x00}},
{0x92,1,{0x06}},
{0x93,1,{0x40}},
{0x94,1,{0x00}},
{0x95,1,{0x00}},
{0x96,1,{0x00}},
{0x99,1,{0x0D}},
{0x9A,1,{0x36}},
{0x9B,1,{0x0C}},
{0x9C,1,{0x9E}},
{0x44,1,{0x33}},
{0x45,1,{0x0E}},
{0xA9,1,{0x46}},
{0xAA,1,{0x40}},
{0xAB,1,{0x52}},
{0xAC,1,{0x4E}},
{0xAD,1,{0x6C}},
{0xAE,1,{0x34}},
{0xAF,1,{0x72}},
{0xB0,1,{0x58}},
{0xB1,1,{0x4C}},
{0xB2,1,{0x48}},
{0xB3,1,{0x54}},
{0xB4,1,{0x74}},
{0xB5,1,{0x42}},
{0xB6,1,{0x78}},
{0xB7,1,{0x2E}},
{0xB8,1,{0x3A}},
{0xB9,1,{0x66}},
{0xBA,1,{0x5E}},

{0xFF,1,{0x27}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0x13,1,{0x00}},
{0x14,1,{0x55}},
{0x1F,1,{0x55}},

////////////////////////////////
//////////// modified //////////
////////// 38% -> 36% //////////
////////////////////////////////
{0xFF,1,{0x24}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0x8D,1,{0x80}},
{0x3A,1,{0x9C}},
{0x5A,1,{0x9C}},
//2020/03/04 modify
{0x5D,1,{0x08}},
{0x88,1,{0x32}},
{0x89,1,{0xC0}},
{0x8E,1,{0x08}},

{0xFF,1,{0x25}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0x56,1,{0xA3}},
{0x46,1,{0x70}},
{0x47,1,{0x38}},
{0x1F,1,{0x9C}},
{0x26,1,{0x9C}},
{0x33,1,{0x9C}},
{0x42,1,{0x9C}},
{0x4B,1,{0x9C}},
{0x4F,1,{0x9C}},
{0x5D,1,{0x9C}},
{0x61,1,{0x9C}},

{0xFF,1,{0x26}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0x31,1,{0x91}},
{0x63,1,{0x9C}},
{0x67,1,{0x9C}},
{0x73,1,{0x9C}},
{0x7A,1,{0x9C}},
{0x82,1,{0x9C}},
{0x86,1,{0x9C}},

///////////////////////////////////////
////////////// 2020/03/16 /////////////
////// New VDS VSD GCH test code //////
///////////////////////////////////////
{0xFF,1,{0x24}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0x01,1,{0x22}},
{0x06,1,{0x1C}},
{0x07,1,{0x1C}},
{0x17,1,{0x22}},
{0x1C,1,{0x1C}},
{0x1D,1,{0x1C}},
{0x86,1,{0x14}},

{0xFF,1,{0x10}},
{REGFLAG_DELAY, 1, {}},
{0xFB,1,{0x01}},
{0xBA,1,{0x03}},
{0x35,1,{0x00}},
{0x11,1,{0x00}},
{REGFLAG_DELAY, 100, {}},
{0x29,1,{0x00}},
{REGFLAG_DELAY, 20, {}},
//-------------  Display Initial Setting end -------------------------
{REGFLAG_END_OF_TABLE, 0x00, {}}    
};

static void push_table(struct LCM_setting_table *table, unsigned int count, unsigned char force_update)
{
    unsigned int i;

    for (i = 0; i < count; i++)
    {
        unsigned cmd;
        cmd = table[i].cmd;

        switch (cmd)
        {
        case REGFLAG_DELAY:
            if (table[i].count <= 10)
                MDELAY(table[i].count);
            else
                MDELAY(table[i].count);
            break;

        case REGFLAG_END_OF_TABLE:
            break;

        default:
            dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
        }
    }
}

/* --------------------------------------------------------------------------- */
/* LCM Driver Implementations */
/* --------------------------------------------------------------------------- */

static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
{
	memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
}

static void lcm_get_params(LCM_PARAMS *params)
{
	memset(params, 0, sizeof(LCM_PARAMS));

	params->type                         = LCM_TYPE_DSI;
	params->width                        = FRAME_WIDTH;
	params->height                       = FRAME_HEIGHT;

	#ifndef BUILD_LK
	params->physical_width               = 68;
	params->physical_height              = 151;
	params->physical_width_um            = 67930;
	params->physical_height_um           = 150960;
	params->density                      = 320;
	#endif

	// enable tearing-free
	params->dbi.te_mode                  = LCM_DBI_TE_MODE_VSYNC_ONLY;
	params->dbi.te_edge_polarity         = LCM_POLARITY_RISING;

	#if (LCM_DSI_CMD_MODE)
	params->dsi.mode                     = CMD_MODE;
	params->dsi.switch_mode              = SYNC_PULSE_VDO_MODE;
	#else
	params->dsi.mode                     = SYNC_PULSE_VDO_MODE;//SYNC_EVENT_VDO_MODE;//BURST_VDO_MODE;////
	#endif

	// DSI
	/* Command mode setting */
	//1 Three lane or Four lane
	params->dsi.LANE_NUM                 = LCM_FOUR_LANE;
	//The following defined the fomat for data coming from LCD engine.
	params->dsi.data_format.color_order  = LCM_COLOR_ORDER_RGB;
	params->dsi.data_format.trans_seq    = LCM_DSI_TRANS_SEQ_MSB_FIRST;
	params->dsi.data_format.padding      = LCM_DSI_PADDING_ON_LSB;
	params->dsi.data_format.format       = LCM_DSI_FORMAT_RGB888;

	params->dsi.PS                       = LCM_PACKED_PS_24BIT_RGB888;

	#if (LCM_DSI_CMD_MODE)
	params->dsi.intermediat_buffer_num   = 0;//because DSI/DPI HW design change, this parameters should be 0 when video mode in MT658X; or memory leakage
	params->dsi.word_count               = FRAME_WIDTH * 3; //DSI CMD mode need set these two bellow params, different to 6577
	#else
	params->dsi.intermediat_buffer_num   = 2;	//because DSI/DPI HW design change, this parameters should be 0 when video mode in MT658X; or memory leakage
	#endif

	// Video mode setting
	params->dsi.packet_size              = 256;
	params->dsi.vertical_sync_active     = 4;
	params->dsi.vertical_backporch       = 6;
	params->dsi.vertical_frontporch      = 10;
	params->dsi.vertical_active_line     = FRAME_HEIGHT;

	params->dsi.horizontal_sync_active   = 4;
	params->dsi.horizontal_backporch     = 100;//36
	params->dsi.horizontal_frontporch    = 110;//78
	
	params->dsi.horizontal_active_pixel  = FRAME_WIDTH;
	/* params->dsi.ssc_disable = 1; */

	params->dsi.PLL_CLOCK                = 290;//270
	//params->dsi.ssc_disable                         = 0;
	//params->dsi.ssc_range                           = 4;
	params->dsi.esd_check_enable = 1;
	params->dsi.customization_esd_check_enable = 1;
	params->dsi.lcm_esd_check_table[0].cmd          = 0x0a;
	params->dsi.lcm_esd_check_table[0].count        = 1;
	params->dsi.lcm_esd_check_table[0].para_list[0] = 0x9c;
}



static unsigned int lcm_compare_id(void)
{
	unsigned int id = 0;
	unsigned char buffer[2];
	unsigned int array[16];
	
	//prize-add-pengzhipeng-20191128-start
	int ret = 0;

	/*config rt5081 register 0xB2[7:6]=0x3, that is set db_delay=4ms.*/
	ret = PMU_REG_MASK(0xB2, (0x3 << 6), (0x3 << 6));

	/* set AVDD 5.4v, (4v+28*0.05v) */
	/*ret = RT5081_write_byte(0xB3, (1 << 6) | 28);*/
	ret = PMU_REG_MASK(0xB3, 28, (0x3F << 0));
	if (ret < 0)
		dprintf("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB3);
	else
		dprintf("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB3);

	/* set AVEE */
	/*ret = RT5081_write_byte(0xB4, (1 << 6) | 28);*/
	ret = PMU_REG_MASK(0xB4, 28, (0x3F << 0));
	if (ret < 0)
		dprintf("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB4);
	else
		dprintf("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB4);

	/* enable AVDD & AVEE */
	/* 0x12--default value; bit3--Vneg; bit6--Vpos; */
	/*ret = RT5081_write_byte(0xB1, 0x12 | (1<<3) | (1<<6));*/
	ret = PMU_REG_MASK(0xB1, (1<<3) | (1<<6), (1<<3) | (1<<6));
	if (ret < 0)
		dprintf("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB1);
	else
		dprintf("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB1);
//prize-add-pengzhipeng-20191128-end

	LCM_LOGI("%S: enter\n", __func__);

	SET_RESET_PIN(1);
	MDELAY(10);
	SET_RESET_PIN(0);
	MDELAY(10);
	SET_RESET_PIN(1);
	MDELAY(10);

	array[0] = 0x00023700;	/* read id return two byte,version and id */
	dsi_set_cmdq(array, 1, 1);

	read_reg_v2(0xDB, buffer, 1);
	id = buffer[0];

	LCM_LOGI("%s,nt35695_id=0x%08x\n", __func__, id);
	
	if (id == LCM_ID_NT36525_TIANMA)
		return 1;
	else
		return 0;

    return 0;
}

static void lcm_init(void)
{
//prize-add-pengzhipeng-20191128-start
	int ret = 0;

	/*config rt5081 register 0xB2[7:6]=0x3, that is set db_delay=4ms.*/
	ret = PMU_REG_MASK(0xB2, (0x3 << 6), (0x3 << 6));

	/* set AVDD 5.4v, (4v+28*0.05v) */
	/*ret = RT5081_write_byte(0xB3, (1 << 6) | 28);*/
	ret = PMU_REG_MASK(0xB3, 28, (0x3F << 0));
	if (ret < 0)
		dprintf("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB3);
	else
		dprintf("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB3);

	/* set AVEE */
	/*ret = RT5081_write_byte(0xB4, (1 << 6) | 28);*/
	ret = PMU_REG_MASK(0xB4, 28, (0x3F << 0));
	if (ret < 0)
		dprintf("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB4);
	else
		dprintf("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB4);

	/* enable AVDD & AVEE */
	/* 0x12--default value; bit3--Vneg; bit6--Vpos; */
	/*ret = RT5081_write_byte(0xB1, 0x12 | (1<<3) | (1<<6));*/
	ret = PMU_REG_MASK(0xB1, (1<<3) | (1<<6), (1<<3) | (1<<6));
	if (ret < 0)
		dprintf("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB1);
	else
		dprintf("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB1);
//prize-add-pengzhipeng-20191128-end
	MDELAY(10);
    MDELAY(5);
    SET_RESET_PIN(1);
    MDELAY(5);
    SET_RESET_PIN(0);
    MDELAY(5);
    SET_RESET_PIN(1);
    MDELAY(10);
    
    push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
}

static void lcm_suspend(void)
{
//prize-add-pengzhipeng-20191128-start
	int ret = 0;
//prize-add-pengzhipeng-20191128-end
    push_table(lcm_suspend_setting, sizeof(lcm_suspend_setting) / sizeof(struct LCM_setting_table), 1);

    SET_RESET_PIN(1);
    MDELAY(5);
//prize-add-pengzhipeng-20191128-start
	ret = PMU_REG_MASK(0xB1, (0<<3) | (0<<6), (1<<3) | (1<<6));
	if (ret < 0)
		dprintf("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB1);
	else
		dprintf("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB1);

	MDELAY(5);
//prize-add-pengzhipeng-20191128-end
}

static void lcm_resume(void)
{
    lcm_init();
}

LCM_DRIVER nt36525_hdp_dsi_vdo_boe_drip_incell_lcm_drv =
{
    .name			= "nt36525_hdp_dsi_vdo_boe_drip_incell",
#if defined(CONFIG_PRIZE_HARDWARE_INFO) && !defined (BUILD_LK)
	.lcm_info = {
		.chip	= "NT36525",
		.vendor	= "nvt",
		.id		= "0x72",
		.more	= "720*1600",
	},
#endif
    .set_util_funcs = lcm_set_util_funcs,
    .get_params     = lcm_get_params,
    .init           = lcm_init,
    .suspend        = lcm_suspend,
    .resume         = lcm_resume,
    .compare_id     = lcm_compare_id,
};
